﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using System.Threading;

namespace XMM
{
    /// <summary>
    /// Interaktionslogik für ProcessingSplash.xaml
    /// </summary>
    public partial class ProcessingSplash : Window
    {
        Thread thStatusLoop;

        int iCurrentValue = 0;

        public ProcessingSplash()
        {
            InitializeComponent();
        }

        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            thStatusLoop = new Thread(new ThreadStart(loopStatus));
            thStatusLoop.Start();
        }

        private void loopStatus()
        {
            while(true)
            {
                if (iCurrentValue >= 96)
                {
                    this.Dispatcher.Invoke(new setValueCallback(setValue), new object[] { 0 });
                }
                else
                {
                    this.Dispatcher.Invoke(new setValueCallback(setValue), new object[] { iCurrentValue + 4 });
                }
                Thread.Sleep(500);
            }
        }

        private void setValue(int iNewValue)
        {
            if (iNewValue > 100)
                iNewValue = 100;

            iCurrentValue = iNewValue;
            pbStatus.Value = iNewValue;
        }

        private delegate void setValueCallback(int iNewValue);
    }
}
